home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Yerk 3.64 / Supplement / my stuff / offscreen < prev    next >
Text File  |  1991-01-01  |  2KB  |  88 lines

  1. \    rfl    writing to offscreen bitmaps
  2.  
  3. :CLASS bitMap  <Super barray
  4.  
  5.     Var        BaseAddr
  6.     Int        RowBytes
  7.     Rect    BndsRect
  8.  
  9.     \ (  n  l t r b -- )
  10.     :M  PUT:   Put:  bndsRect  Put: RowBytes
  11.         idxbase +base Put: BaseAddr  ;M
  12.  
  13. ;CLASS
  14.  
  15. :CLASS copier <super grafPort
  16.  
  17.     var        destPort    \ destination grafPort (abs)
  18.     rect    destRect    \ destination rectangle
  19.     var        offscreen    \ hold copy of bitmap address
  20.     int        mode        \ copy mode
  21.  
  22. \ **** initialize ****
  23.  
  24.   :M mode: ( n --) put: mode ;M
  25.  
  26.   :M destPort: ( window --) +base put: destPort ;M
  27.  
  28.   :M destRect: ( l t r b --)  put: destRect ;M
  29.  
  30. \ **** creation ****
  31.  
  32.   :M open: (abs) call openPort ;M
  33.  
  34.   :M rowBytes: ( -- n) size: destRect drop 15 + 4 >> 1 << ;M
  35.  
  36.   :M new: { \ myBitMap rows -- }
  37.     open: self
  38.     rowBytes: self -> rows                \ calc rowbytes
  39.     rows size: destRect swap drop *        \ calc size of bitmap
  40.     heap> bitMap -> myBitMap            \ create bitmap on heap
  41.     rows get: destRect put: myBitMap    \ init bitmap
  42.     myBitMap put: offScreen                \ store pointer for disposing
  43.     pushPort set: self                    \ set bitmap to grafport
  44.     myBitMap +base call setPortBits
  45.     get: destRect ^base 16 + put: rect
  46.     popPort ;M
  47.  
  48.   :M close: (abs) call closePort dispose: offscreen ;M
  49.  
  50. \ *** manipulation ****
  51.  
  52.   :M draw: ^base 2+ +base obj: destPort 2+
  53.     (abs) 16 +  abs: destRect
  54.     int: mode
  55.     get: destPort -base 24 + @ call copyBits ;M    \ draw in visrgn of destPort
  56.  
  57.   :M save: obj: destPort 2+ ^base 2+ +base
  58.     abs: destRect (abs) 16 +
  59.     word0 get: destPort -base 24 + @ call copyBits ;M    \ write over previous
  60.  
  61.   :M offset: ( dx dy -- ) offset: destRect ;M
  62.  
  63.   :M moveTo: { x y -- } x getTopX: destRect - y getTopY: destRect -
  64.     offset: destRect ;M
  65.  
  66.   :M clear: clear: [ obj: offScreen ] ;M
  67.  
  68. ;CLASS
  69.  
  70. \ example
  71. \ copier bob
  72. \ 30 30 130 130 destrect: bob \ getrect: myPort destrect: bob
  73. \ fwind destport: bob
  74. \ new: bob
  75. \ set: fwind
  76. \ to draw into offscreen bitmap: 'set: bob' then all output to
  77. \   screen goes offscreen. To draw bitmap to desport, 'draw: bob'
  78. \ to save what is in destrect in destport, 'save: bob'.
  79.  
  80. \ sequence should be
  81. \ destrect, destport, mode?
  82. \ new:  which creates bitmap, stores into grafport, and putrect
  83.  
  84. \ Any rectangular area within a window could be the destrect, even the
  85. \  port.rect. save: copies the window into the offscreen bitmap
  86. \  and draw: will return it to the window.
  87. \ Alternatively, one could set: the copier object, draw into it,
  88. \  then draw:...this will draw into the visrgn of the dest window.